#pragma once

#include "UMLAssociationEndLabel.h"

#include "../uml/Property.h"

namespace uml {

UMLAssociationEndLabel::UMLAssociationEndLabel(const QString& umlType)
    : UMLLabel(umlType) {}

void UMLAssociationEndLabel::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    UMLLabel::fromJson(json, errorList);
    modelElement_ = JsonSerializable::create<Property>(json.value("modelElement"), errorList);

}

void UMLAssociationEndLabel::toJson(QJsonObject& json) {
    UMLLabel::toJson(json);
    if (modelElement_) {
        QJsonObject modelElement_json;
        modelElement_->toJson(modelElement_json);
        json.insert("modelElement", modelElement_json);
    }
}

/// <summary>
/// modelElement getter
/// Restricts UMLAssociationEndLabels to show only Properties (that are
/// AssociationEnds, see constraint).
/// </summary>
shared_ptr<Property> UMLAssociationEndLabel::modelElement() const {
    return modelElement_;
}

/// <summary>
/// modelElement setter
/// Restricts UMLAssociationEndLabels to show only Properties (that are
/// AssociationEnds, see constraint).
/// </summary>
void UMLAssociationEndLabel::setModelElement(shared_ptr<Property> value) {
    modelElement_ = value;
}

} // namespace uml
